import java.util.Scanner;
public class XX {
  public static void main(String args[]) {
   int i=1;
   int m,n;
   System.out.println("输入m和n，求m模n的逆元(m+空格+n+回车)");
   Scanner s = new Scanner(System.in);
   System.out.print("输入m: ");
   m=s.nextInt();
   System.out.print("输入n:");
   n=s.nextInt();
   for(i=1;i<999;i++)
     if(m*i%n==1) {
       System.out.println(m+"模"+n+"的逆元是"+i);
       break;}
}
}

